import java.util.Random;
import java.util.Scanner;
import java.text.NumberFormat;

public class Zhenfenshu {
    Random r = new Random();
    Scanner reader = new Scanner(System.in);
    FundCalculate f=new FundCalculate();
    Judgement jud = new Judgement();
    Judgement j = new Judgement();
    NumberFormat num = NumberFormat.getPercentInstance();//调用getPercentInstance方法
    public void makeAndCalculate(int n){
        char[] op = new char[]{'+', '-', '*'};
        for(int i=0;i<n;i++){
            int num[]=new int[4];//产生安放四个数字的数组
            for(int j=0;j<4;j++)
                num[j]=r.nextInt(20)+1;//生成随机数
            int s=r.nextInt(3);
            String ex=String.valueOf(num[0])+"/"+String.valueOf(num[1])+String.valueOf(op[s])+String.valueOf(num[2])+"/"+String.valueOf(num[3])+"=";
            System.out.println(ex);//输出算式
            WAndRFile write=new WAndRFile();
            write.writeToFile(ex);
            String ua=reader.next();//用户输入答案
            ua=ex+ua;
            String ca=new String();
            if(s==2){//计算真分数乘法运算
                int nu[]=new int[2];
                nu[0]=num[0]*num[2];
                nu[1]=num[1]*num[3];
                ca=ex+f.yuefen(nu[0],nu[1]);//将计算结果约分
            }
            else if(s==0){//计算真分数加法运算
                int nu_1[]=new int[2];
                nu_1[0]= num[0]*num[3]+num[1]*num[2];
                nu_1[1]= num[1]*num[3];
                ca=ex+f.yuefen(nu_1[0],nu_1[1]);
            }
            else {//计算真分数减法运算
                int nu_2[]=new int[2];
                nu_2[0]= num[0]*num[3]-num[1]*num[2];
                nu_2[1]= num[1]*num[3];
                if(nu_2[0]<0){//分子为负数时
                    nu_2[0]=-nu_2[0];//取反
                    ca=ex+"-"+f.yuefen(nu_2[0],nu_2[1]);//加上负号
                }
                else
                    ca=ex+f.yuefen(nu_2[0],nu_2[1]);
            }
            System.out.println("以下是从终端计算情况：");
            Boolean result=ua.equals(ca);
            jud.judgeFormula(result,ca);


        }
        double T_1 = (double) jud.getTrues()/n;
        System.out.println("正确率为："+num.format(T_1));
    }
}
